package com.shzu.jwc.ty.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shzu.jwc.ty.common.Msg;
import com.shzu.jwc.ty.bean.ProblemClass;
import com.shzu.jwc.ty.service.ProblemClassService;

@Controller
@RequestMapping("problemclass")
public class ProbleClasscontroller {

	@Autowired
	ProblemClassService problemclassservice;
	
	@RequestMapping("/probleclassshow.action")
	public String showproblemclass(Model model)
	{
		List<ProblemClass> problemclass=problemclassservice.getproblemclass();
		model.addAttribute("data",problemclass);
		return "/problemclass/problemclass";
	}
	
	@ResponseBody
	@RequestMapping("/getproblemclass.action")
	public Msg getproblemclass()
	{
		List<ProblemClass> problemclass=problemclassservice.getproblemclass();
		return Msg.success("获取成功").add("data",problemclass );
	}
	
	@ResponseBody
	@RequestMapping("/updateproblemclass.action")
	public Msg update(@RequestParam("column") String column,@RequestParam("value") String value,@RequestParam("id") Integer id)
	{
		if(problemclassservice.updatepro(id, column, value)>0)
			return Msg.success("修改成功");
		else
			return Msg.error("修改失败");
	}
	
	@ResponseBody
	@RequestMapping("/addproblemclass.action")
	public Msg addproblemclass(ProblemClass problemClass)
	{
		if(problemclassservice.add(problemClass)>0)
			return Msg.success("插入成功");
		else
			return Msg.error("插入失败");
	}
	
	@ResponseBody
	@RequestMapping("/deleteproblemclass.action")
	public Msg deleteproblemclass(@RequestParam("id") Integer problemClassId)
	{
		if(problemclassservice.delete(problemClassId)>0)
			return Msg.success("删除成功");
		else
			return Msg.error("删除失败");
	}
}
